package com.itheima03;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author Xiao
 * @date 2021/7/14
 */
public class ListDemo {
    /**
     *      Collection _ List
     */
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("aa");
        list.add("bb");
        list.add("cc");
        list.add("aa");
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            String s = it.next();
            System.out.println(s);
        }
        System.out.println(list);   //[aa, bb, cc, aa]
        list.add(2,"bb");       //[aa, bb, bb, cc, aa]
        list.remove("aa");  //只能删除第一个"aa"
        System.out.println(list);   //[bb, bb, cc, aa]
        list.remove(2);
        System.out.println(list);
        list.set(2,"00");
        System.out.println(list);
        System.out.println(list.get(2));
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            System.out.println(s);
        }
    }
}
